﻿<UserControl x:Class="QLab.UserControls.EditableTextBlock"
             xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
             xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
             xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" 
             xmlns:d="http://schemas.microsoft.com/expression/blend/2008" 
             xmlns:local="clr-namespace:QLab.UserControls"
             xmlns:qlab="clr-namespace:QLab"
             x:Name="mainControl"
             mc:Ignorable="d" 
             d:DesignHeight="300" d:DesignWidth="300">
    <UserControl.Resources>
        <DataTemplate x:Key="EditModeTemplate">
            <TextBox KeyDown="TextBox_KeyDown" 
                     Loaded="TextBox_Loaded" 
                     LostFocus="TextBox_LostFocus"
                     Text="{Binding ElementName=mainControl, Path=Text, UpdateSourceTrigger=PropertyChanged}"
                     Margin="0" 
                     FontSize="{Binding Source={x:Static Member=qlab:Properties.Settings.Default}, Path=ListFontSize, Mode=OneWay}"
                     BorderThickness="1" 
                     Padding="-1 0 -1 0" />
        </DataTemplate>

        <DataTemplate x:Key="DisplayModeTemplate">
            <TextBlock Text="{Binding ElementName=mainControl, Path=FormattedText}"  /><!--Margin="5,3,5,3"-->
        </DataTemplate>

        <Style TargetType="{x:Type local:EditableTextBlock}">
            <Style.Triggers>
                <Trigger Property="IsInEditMode" Value="True">
                    <Setter Property="ContentTemplate" Value="{StaticResource EditModeTemplate}" />
                </Trigger>
                <Trigger Property="IsInEditMode" Value="False">
                    <Setter Property="ContentTemplate" Value="{StaticResource DisplayModeTemplate}" />
                </Trigger>
            </Style.Triggers>
        </Style>
    </UserControl.Resources>
</UserControl>
